package practice.library.akka

import akka.actor.{Actor, ActorSystem, Props}
import akka.actor.Actor.Receive

/**
  * Created by lovepocky(lovepocky@foxmail.com) on 2016/4/14.
  */
object AkkaPractice {
	def main(args: Array[String]) {
		implicit val system = ActorSystem("Akka-Practice-System")
		println(s"system.child: ${system.child("childPath") }")
		println(s"system.name: ${system.name }")
		println(s"system./(): ${system / "test" }")
		println(s"system.startTime: ${system.startTime }")
		println(s"system.whenTerminated: ${system.whenTerminated }")
		
		val actorRef = system.actorOf(Props[TypicalActor], "test")
		println(s"actorRef.path: ${actorRef.path }")
		
		system.terminate()
	}
	
	case class TypicalMessage(key: String, value: String)
	
	class TypicalActor extends Actor {
		
		import akka.event.Logging
		
		val log = Logging(context.system, this)
		
		override def receive: Receive = {
			case TypicalMessage(key, value) =>
				log.info(s"Received Typical Message: key -> $key, value -> $value")
			case _ =>
				log.info("Received Something unknown")
		}
	}
	
}
